package cn.mst.vrs.dal.mysql.venue;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.mst.vrs.controller.admin.venue.vo.VenuePageReqVO;
import cn.mst.vrs.dal.dataobject.venue.VenueDO;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.ChainWrappers;
import org.apache.ibatis.annotations.Mapper;

/**
 * 体育场馆 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface VenueMapper extends BaseMapperX<VenueDO> {

    default PageResult<VenueDO> selectPage(VenuePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<VenueDO>()
                .eqIfPresent(VenueDO::getTypeId, reqVO.getTypeId())
                .eqIfPresent(VenueDO::getCode, reqVO.getCode())
                .likeIfPresent(VenueDO::getName, reqVO.getName())
                .eqIfPresent(VenueDO::getDescription, reqVO.getDescription())
                .eqIfPresent(VenueDO::getOpenedAt, reqVO.getOpenedAt())
                .eqIfPresent(VenueDO::getClosedAt, reqVO.getClosedAt())
                .eqIfPresent(VenueDO::getPrice, reqVO.getPrice())
                .eqIfPresent(VenueDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(VenueDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(VenueDO::getId));
    }

    default Page<VenueDO> selectSearchPage(Page<VenueDO> page, String keyword) {
        return ChainWrappers.lambdaQueryChain(this)
                .like(StrUtil.isNotBlank(keyword), VenueDO::getName, keyword)
                .or()
                .like(StrUtil.isNotBlank(keyword), VenueDO::getDescription, keyword)
                .page(page);
    }
}